package com.tutu.service.impl;

import com.tutu.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MenuServiceImpl implements MenuService {

    @Autowired
    WxMpService wxMpService;

    @Autowired
    WxMenu wxMenu;

    public void initMenu() {
        try {
            // 删除旧菜单
            log.info("开始删除微信公众号旧菜单...");
            wxMpService.getMenuService().menuDelete();
            log.info("微信公众号旧菜单删除成功！");

            // 创建新菜单
            log.info("开始初始化微信公众号新菜单...");
            wxMpService.getMenuService().menuCreate(wxMenu);
            log.info("微信公众号新菜单初始化成功！");
        } catch (WxErrorException e) {
            System.err.println("菜单创建失败: " + e.getMessage());
        }
    }
}
